<template>
  <div class="conMain relative">
    <!--自动刷新,刷新,多单齐发-->
    <div class="his-item">
      <a href="javascript:void(0)" class="hint auto">
        <div class="auto-load" @click="onOffRefresh">
          <div :class="['on-off', isON ? 'on' : 'off']">
            <div class="on">
              <span class="on-off-icon"></span>
              <span class="on-off-text"></span>
            </div>
            <div class="off">
              <span class="on-off-text"></span>
              <span class="on-off-icon"></span>
            </div>
          </div>
        </div>
        <span class="hint-txt">自动刷新</span>
      </a>
      <a href="javascript:void(0)" class="hint refresh" @click="refreshFn()">
        <span class=""></span>
        <span class="hint-txt">刷新</span>
      </a>
      <a href="javascript:void(0)" class="hint more" @click="releaseMoreFn()">
        <span class=""></span>
        <span class="hint-txt">今日单多单选择一起发布</span>
      </a>
    </div>
    <!--详情-->
    <div class="side-left">
      <!--待发布-->
      <div v-if="handle.handle == 0">
        <h3>输送单详情</h3>
        <div class="detail">
          <span>扫码编号</span>
          <div>
            {{ showLis.guid }} <i>{{ showLis.createdtime }}</i>
          </div>
        </div>
        <div class="detail" v-if="showLis.fixedtime != ''">
          <span class="red">预约时间</span>
          <div>{{ showLis.fixedtime }}</div>
        </div>
        <div class="detail">
          <span>输送类型</span>
          <div>{{ showLis.dept }}</div>
        </div>
        <div class="detail">
          <span>输送起点</span>
          <div>{{ showLis.askdept }}</div>
        </div>
        <div class="detail">
          <span>起点床号</span>
          <div>{{ showLis.name }} 床号:{{ showLis.bedno }}</div>
        </div>
        <div class="detail">
          <span>输送终点</span>
          <div>{{ showLis.address }}</div>
        </div>
        <div class="detail">
          <span>终点床号</span>
          <div></div>
        </div>
        <div class="detail">
          <span>前往方式</span>
          <div>{{ showLis.tour }}</div>
        </div>
        <div class="detail">
          <span>下单备注</span>
          <div>{{ showLis.memo }}</div>
        </div>
        <div class="detail" v-if="showLis.guid != '' && handle.today != 2">
          <span>订单状态</span>
          <div>{{ showLis.statu == 2 ? "已预约明天发布" : "待发布" }}</div>
        </div>
        <div
          class="handle"
          v-if="showLis.guid != '' && handle.today == 0 && showLis.statu != 2"
        >
          <button
            class="btn"
            :class="{ act: release == true }"
            @click="releaseFn(showLis.id)"
          >
            直接发布</button
          ><!--为发布的-->
          <button
            class="btn"
            :class="{ act: release == true }"
            @click="alterFn(showLis.id)"
          >
            修改发布</button
          ><!--为发布的-->
        </div>
        <div
          class="handle"
          v-if="showLis.guid != '' && handle.today == 1 && showLis.statu != 2"
        >
          <button
            class="btn"
            :class="{ act: release == true }"
            @click="toThisDayReleaseFn()"
          >
            改为今日发布</button
          ><!--为发布的-->
          <button
            class="btn"
            :class="{ act: release == true }"
            @click="toThisDayAlterFn()"
          >
            编辑后今日发布</button
          ><!--为发布的-->
          <button
            class="btn"
            :class="{ act: release == true }"
            @click="appointmentFn()"
          >
            预约明天发布</button
          ><!--为发布的-->
        </div>
      </div>
      <!--已发单-->
      <div v-else>
        <div class="handle">
          <h3>输送单详情</h3>
          <div class="detail">
            <span>扫码编号</span>
            <div>
              {{ issueShowLis.sn }} <i>{{ issueShowLis.createdtime }}</i>
            </div>
          </div>
          <div class="detail">
            <span>发布时间</span>
            <div>{{ issueShowLis.hiscreatedtime }}</div>
          </div>
          <div class="detail">
            <span>输送类型</span>
            <div>{{ issueShowLis.catalogname }}</div>
          </div>
          <div class="detail">
            <span>输送起点</span>
            <div>{{ issueShowLis.startaddress }}</div>
          </div>
          <div class="detail">
            <span>起点床号</span>
            <div>{{ issueShowLis.startbed }}</div>
          </div>
          <div class="detail">
            <span>输送终点</span>
            <div>{{ issueShowLis.finishaddress }}</div>
          </div>
          <div class="detail">
            <span>终点床号</span>
            <div>{{ issueShowLis.finishbed }}</div>
          </div>
          <div class="detail">
            <span>前往方式</span>
            <div>{{ issueShowLis.tackle }}</div>
          </div>
          <div class="detail">
            <span>下单备注</span>
            <div>
              <p>{{ issueShowLis.message }}</p>
              {{
                issueShowLis.appointment != issueShowLis.hiscreatedtime
                  ? "预定" + issueShowLis.appointment + "派送"
                  : ""
              }}
            </div>
          </div>
          <div class="detail">
            <span>接单人</span>
            <div>
              <i v-for="item in issueShowLis.receive">{{ item.receive }}</i>
            </div>
          </div>
          <div class="detail">
            <span>订单状态</span>
            <div>
              <i
                v-if="
                  issueShowLis.attribute == 4 || issueShowLis.attribute == 9
                "
                >已销单
                {{
                  issueShowLis.completetime.substr(
                    issueShowLis.completetime.length - 8
                  )
                }}</i
              >
              <i v-else>
                {{ $root.$data.sStatus[issueShowLis.statu] }}
                <i v-if="issueShowLis.statu == 2">{{
                  issueShowLis.completetime.substr(
                    issueShowLis.completetime.length - 8
                  )
                }}</i>
              </i>
            </div>
          </div>
          <div class="detail">
            <span>订单进度</span>
            <div v-show="issueShowLis.time_flow.length == 0"></div>
            <div v-show="issueShowLis.time_flow.length > 0">
              <ss-fullow :value-data="issueShowLis.time_flow"></ss-fullow>
              <!--<p  v-for="item in issueShowLis.time_flow">{{item.created_at.substring(5)}} {{item.uname}}：{{item.action}}</p>-->
            </div>
          </div>
          <div class="detail">
            <span>派单时间</span>
            <div>{{ issueShowLis.dispatch_time }}</div>
          </div>
          <div class="detail">
            <span>接单时间</span>
            <div>{{ issueShowLis.received_time }}</div>
          </div>
          <div class="detail">
            <span>响应时间</span>
            <div>
              {{
                issueShowLis.received_sec == 0 ? "" : issueShowLis.received_sec
              }}
            </div>
          </div>
          <div class="detail">
            <span>完成时间</span>
            <div>
              {{ issueShowLis.statu == 2 ? issueShowLis.completetime : "" }}
            </div>
          </div>
          <div class="detail">
            <span>完成耗时</span>
            <div>
              {{
                issueShowLis.finshed_sec == 0 ? "" : issueShowLis.finshed_sec
              }}
            </div>
          </div>

          <div class="handle" v-if="handle.today == 0">
            <button
              v-if="
                $root.$data.sOrderAttr[issueShowLis.attribute].badge != '销' ||
                issueShowLis.statu == 3
              "
              :class="['btn', { act: cancel }]"
              @click="showCancelFn()"
            >
              销单
            </button>
            <button
              v-if="issueShowLis.statu != 2"
              class="btn"
              :class="{ act: reminder }"
              @click="reminderFn(issueShowLis.id)"
            >
              催单
            </button>
          </div>
        </div>
      </div>
    </div>
    <!--列表，时间-->
    <div class="side-right">
      <div class="lis">
        <calendar
          :date="startTime"
          :option="option"
          @change="changeDayFn()"
          :sign="after"
        ></calendar>
      </div>
      <div class="lis">
        <h3 class="title" style="padding-right: 124px">
          <span>{{ startTime.time }}　{{ timeDay }}</span>
        </h3>
        <div v-if="isLoad" class="no-txt"><load></load> 正在加载，请稍后</div>
        <div v-else class="el-table his-lis">
          <table v-if="lisLen > 0">
            <colgroup>
              <col width="18%" />
              <col width="12%" />
              <col />
              <col />
            </colgroup>
            <thead>
              <tr>
                <th><div class="cell">姓名</div></th>
                <th><div class="cell">床号</div></th>
                <th>
                  <div class="cell">检查类型（{{ lisLen }}）</div>
                </th>
                <th><div class="cell">预约时间</div></th>
              </tr>
            </thead>
            <tbody>
              <template v-for="(item, index) in lis">
                <tr
                  v-for="(tri, trind) in item.lis"
                  :keys="trind"
                  @click="handleShowInfo(tri)"
                  :class="[
                    'row',
                    showId == tri.id ? 'select' : '',
                    { past: handle.today == 2 },
                  ]"
                >
                  <td v-if="trind == 0" :rowspan="item.lis.length" class="name">
                    <div class="cell">{{ tri.showlis.name }}</div>
                  </td>
                  <td v-if="trind == 0" :rowspan="item.lis.length" class="bed">
                    <div class="bed">{{ item.bed }}</div>
                  </td>
                  <td>
                    <div class="cell">{{ tri.showlis.catalog }}</div>
                  </td>
                  <td>
                    <div class="cell">
                      <span>{{ tri.showlis.time }}</span>
                      <span v-if="tri.showlis.rel == 'del'" class="del-bage"
                        >已销单</span
                      >
                      <span v-else>
                        <span
                          v-if="tri.showlis.class_name == 'tor-issue'"
                          :class="tri.showlis.class_name + '-bage'"
                          >已预约</span
                        >
                        <span
                          v-if="tri.showlis.class_name == 'issue'"
                          :class="tri.showlis.class_name + '-bage'"
                          >已发布</span
                        >
                      </span>
                    </div>
                  </td>
                </tr>
              </template>
            </tbody>
          </table>
          <div v-else class="empty">暂无数据</div>
        </div>
      </div>
    </div>

    <!--多选输送单一起发布-->
    <release-more
      v-if="isMore"
      :list="moreLis"
      :off-dutys="offDuty"
      @close="closeMoreFn"
      @sure="handleUp"
      @printfn="handlePrint"
    ></release-more>
    <!--修改-->
    <his-alter
      v-if="isAlter.show"
      :detail="showLis"
      :off-dutys="offDuty"
      @close="colsAlter"
      @sure="handleUpJson"
    ></his-alter>
    <!--明天-->
    <his-tomorrow
      v-if="isTomorrow.show"
      :type="isTomorrow.type"
      :detail="showLis"
      @colse="closeTom"
      @sure="sureTomorrow"
    ></his-tomorrow>
    <!--销单二次确认-->
    <his-del
      v-if="isCancel"
      :detail="issueShowLis"
      @colse="closeCancel"
      @sure="cancelFn"
    ></his-del>
    <!-- 故障排除 -->
    <troubleShootingBox
      v-show="troubleShootingBoxShow && isSixthHospital"
      @closeTroubleShootingBox="closeTroubleShootingBox"
    ></troubleShootingBox>
    <div class="fasterCon" v-if="state">扫码列表</div>
  </div>
</template>
<script>
import calendar from "../tips/calendar.vue";
import today from "../common/today";
import releaseMore from "../components/his-more.vue";
import hisAlter from "../components/his-alter.vue";
import hisTomorrow from "../components/his-tomorrow.vue";
import hisDel from "../components/his-handle.vue";
import load from "../tips/load.vue";
import SsFullow from "../tips/SsFollow.vue";
import { formatSeconds } from "../common/com.js";
import troubleShootingBox from "../tips/troubleShootingBox.vue";
import {
  cancelUrl,
  editUrl,
  tomorrowUrl,
  alterUrl,
  releaseUrl,
  infoUrl,
  remindUrl,
} from "../common/ajax";
export default {
  components: {
    calendar,
    "release-more": releaseMore,
    "his-alter": hisAlter,
    "his-tomorrow": hisTomorrow,
    "his-del": hisDel,
    load,
    "ss-fullow": SsFullow,
    troubleShootingBox,
  },
  props: {
    start: "",
    roomLis: "",
    offDuty: "",
    todayTime: "",
    hisks: "",
  },
  data() {
    return {
      createdTime: "",
      setBadStatus: true,
      //
      showId: "",
      showLis: {},
      issueShowLis: {},
      lis: [],
      lisLen: 0,
      //状态
      handle: {
        today: -1, //0 今日单，1 明日单，2 其他单
        handle: 0, //0 未发布，1已发布
      },
      release: true, //直接发布/多单发布的布尔值
      isAlter: {
        type: 1,
        show: false,
      }, //修改发布
      isTomorrow: {
        type: 1,
        show: false,
      }, //
      isMore: false,
      moreLis: [],
      isCancel: false,
      cancel: true, //销单
      reminder: true,
      isLoad: false,
      //提示
      state: false,
      //日历
      startTime: {
        time: today.init("YY-MM-DD"),
      },
      option: {
        type: "day",
        week: ["一", "二", "三", "四", "五", "六", "日"],
        month: [
          "一月",
          "二月",
          "三月",
          "四月",
          "五月",
          "六月",
          "七月",
          "八月",
          "九月",
          "十月",
          "十一月",
          "十二月",
        ],
        format: "YYYY-MM-DD",
        placeholder: "when?",
        inputStyle: {
          display: "inline-block",
          padding: "6px",
          "line-height": "22px",
          "font-size": "16px",
          border: "2px solid #fff",
          "box-shadow": "0 1px 3px 0 rgba(0, 0, 0, 0.2)",
          "border-radius": "2px",
          color: "#5F5F5F",
        },
        color: {
          header: "#66bea7",
          headerText: "#fff",
        },
        buttons: {
          ok: "确定",
          cancel: "Cancel",
        },
        overlayOpacity: 0.5, // 0.5 as default
        dismissible: true, // as true as default
      },
      after: [
        { year: "", month: "", day: "", sign: false },
        { year: "", month: "", day: "", sign: false },
        { year: "", month: "", day: "", sign: false },
      ],
      setIntervalLis: null,
      //其他操作
      isON: false,
      troubleShootingBoxShow: false,
      isSixthHospital: Cookies.get("categoryid") == 17
    };
  },
  computed: {
    timeDay: function () {
      let day = new Date(this.startTime.time.replace("-", "/")).getDay();
      let text = "";
      switch (day) {
        case 0:
          text = "周日";
          break;
        case 1:
          text = "周一";
          break;
        case 2:
          text = "周二";
          break;
        case 3:
          text = "周三";
          break;
        case 4:
          text = "周四";
          break;
        case 5:
          text = "周五";
          break;
        case 6:
          text = "周六";
          break;
      }
      return text;
    },
  },
  methods: {
    closeTroubleShootingBox(value) {
      this.troubleShootingBoxShow = value;
    },
    //刷新
    refreshFn() {
      this.loadSign();
      this.loadLis(1, this.startTime.time);
      this.handle.today = -1;
    },
    onOffRefresh() {
      if (this.isON == false) {
        //开启自动刷新
        let _this = this;
        this.isON = true;
        window.clearInterval(_this.setIntervalLis);
        this.setIntervalLis = window.setInterval(_this.refreshFn, 16000);
        sessionStorage.setItem("autoRefresh", _this.setIntervalLis);
      } else {
        this.offFn();
      }
    },
    offFn() {
      let _this = this;
      this.isON = false;
      window.clearInterval(_this.setIntervalLis);
      this.setIntervalLis = "";
    },
    //时间搜索
    changeDayFn() {
      this.offFn();
      this.refreshFn();
    },
    //日歷
    loadSign() {
      jQuery.ajax({
        url: remindUrl,
        type: "post",
        dataType: "json",
        cache: false,
        success: function (data) {
          if (data.success) {
            this.after[0].year = today.getYearDay(
              "YY",
              today.tmr2(0, this.todayTime)
            );
            this.after[0].month = today.getYearDay(
              "MM",
              today.tmr2(0, this.todayTime)
            );
            this.after[0].day = today.getYearDay(
              "DD",
              today.tmr2(0, this.todayTime)
            );
            this.after[0].sign = false;

            this.after[1].year = today.getYearDay(
              "YY",
              today.tmr2(1, this.todayTime)
            );
            this.after[1].month = today.getYearDay(
              "MM",
              today.tmr2(1, this.todayTime)
            );
            this.after[1].day = today.getYearDay(
              "DD",
              today.tmr2(1, this.todayTime)
            );
            this.after[1].sign = data.data.signa;

            this.after[2].year = today.getYearDay(
              "YY",
              today.tmr2(2, this.todayTime)
            );
            this.after[2].month = today.getYearDay(
              "MM",
              today.tmr2(2, this.todayTime)
            );
            this.after[2].day = today.getYearDay(
              "DD",
              today.tmr2(2, this.todayTime)
            );
            this.after[2].sign = data.data.signb;
          } else {
            throwErrorTips("", data.msg);
          }
        }.bind(this),
      });
    },
    //列表
    loadLis(i, time) {
      if (!this.isLoad) {
        this.isLoad = true;
        this.handle.handle = 0;
        this.lis = [];
        this.showLis = { guid: "", id: "", obey: "", statu: "" };
        this.issueShowLis = { attribute: "", id: "", statu: "" };
        let cid = this.$root.$data.cid;
        let atype = "post",
          adata = { opt: i, day: time };
        if (this.$root.$data.lineCid.indexOf(cid) != -1) {
          atype = "get";
          adata = { day: time, ks: this.hisks };
        }
        let m = this.$root.$data.hisErrTips[this.$root.$data.cid] || "";
        jQuery.ajax({
          url: this.$root.$data.hisLisUrl[cid],
          type: atype,
          dataType: "json",
          data: adata,
          cache: false,
          success: function (data) {
            this.isLoad = false;
            if (data.success) {
              //需要根据起点进行过滤  hisorder 未发布
              let d = data.data.hisorder.concat(data.data.reservation);
              this.handleSetLis(d, data.data.iorder, data.data.tomorrow);
              this.lisLen =
                d.length + data.data.iorder.length + data.data.tomorrow.length;
              if (this.$root.$data.cid == "28" && this.lisLen > 0) {
                this.after[0].sign = true;
              }
              this.compTime();
            } else {
              throwErrorTips("HIS单获取失败", data.msg, m);
              this.troubleShootingBoxShow = true;
            }
          }.bind(this),
          error: function (xhr, textStatus) {
            this.isLoad = false;
            this.troubleShootingBoxShow = true;
            throwErrorTips("HIS单获取失败", textStatus, m);
          }.bind(this),
        });
      }
    },
    handleSetLis(lis, iLis, tLis) {
      let gl = [],
        l = [],
        nl = [];
      for (var lval of lis) {
        let o = lval;
        o["showlis"] = {
          names: o.name + " " + o.bedno,
          name: o.name,
          time: o.fixedtime.substring(11) || "",
          catalog: o.dept,
          id: o.guid,
          class_name: "not-issue",
          rel: "not-issue",
        };
        l.push(o);
        gl.push(o.showlis.names);
      }
      for (var tval of tLis) {
        let o = tval;
        o["showlis"] = {
          names: o.name + " " + o.bedno,
          name: o.name,
          time: o.fixedtime.substring(11) || "",
          catalog: o.dept,
          id: o.guid,
          class_name: "tor-issue",
          rel: "tor",
        };
        l.push(o);
        gl.push(o.showlis.names);
      }
      let dels = [],
        wlis = [],
        ilis = [],
        dlis = [];
      for (var val of iLis) {
        let o = val;
        let bed = o.startbed.split(" ");
        o["showlis"] = {
          names: o.startbed,
          name: bed[0],
          time: "",
          catalog: val.catalogname,
          id: val.guid,
          class_name: "issue",
          rel: "issue",
        };
        gl.push(o.showlis.names);
        if (o.attribute == 8) {
          o.showlis.time = o.appointment.substring(11);
        } else if (o.attribute == 9 || o.attribute == 4) {
          o.showlis.rel = "del";
        }
        if (o.statu == 4) {
          l.push(o);
        } else if (o.statu == 1) {
          wlis.push(o);
        } else if (o.statu == 3) {
          ilis.push(o);
        } else {
          o.attribute == 9 ? dels.push(o) : dlis.push(o);
        }
      }
      l = l.concat(wlis, ilis, dlis, dels);
      gl = Array.from(new Set(gl));
      gl.forEach((v) => {
        let o = {
          name: v,
          bed: v.split(" ")[1] || "",
          lis: [],
        };
        l.forEach((val) => {
          if (v == val.showlis.names) {
            o.lis.push(val);
          }
        });
        nl.push(o);
      });
      this.lis = nl.sort(function (a, b) {
        if (/^\d/.test(a.bed) ^ /^\D/.test(b.bed))
          return Number(a.bed) > Number(b.bed) ? 1 : a.bed == b.bed ? 0 : -1;
        return a.bed > b.bed ? -1 : a.bed == b.bed ? 0 : 1;
        //                    return a.bed - b.bed
      });
    },
    //点击查看详情
    // 未发布
    compTime() {
      let d =
        today.getTime2(this.startTime.time) - today.getTime2(this.todayTime);
      if (d == 0) {
        //今
        this.handle.today = 0;
      } else if (d == 86400) {
        //明
        this.handle.today = 1;
      } else {
        //其他
        this.handle.today = 2;
      }
    },
    handleShowInfo(val) {
      this.showId = val.id;
      if (val.showlis.class_name == "issue") {
        this.lookIssueDetail(val.id);
      } else {
        this.showLis = val;
        this.handle.handle = 0;
        this.compTime();
      }
    },
    lookIssueDetail(id) {
      jQuery.ajax({
        url: infoUrl,
        type: "post",
        dataType: "json",
        cache: false,
        data: { oid: id },
        success: function (data) {
          if (data.success) {
            this.issueShowLis = data.data;
            this.issueShowLis.received_sec = formatSeconds(
              this.issueShowLis.received_sec
            );
            this.issueShowLis.finshed_sec = formatSeconds(
              this.issueShowLis.received_sec
            );
            this.handle.handle = 1;

            this.compTime();
          } else {
            throwErrorTips("获取订单详情失败", data.msg);
          }
        }.bind(this),
      });
    },
    //发布post数组,直接发布，多单发布，明天单发布为今日单
    handleUp(arrs) {
      if (this.release == true) {
        this.release = false;
        jQuery.ajax({
          url: releaseUrl,
          type: "post",
          dataType: "json",
          data: { data: JSON.stringify(arrs) },
          cache: false,
          timeout: 1000,
          success: function (data) {
            this.release = true;
            if (data.success) {
              this.$Message({ type: "success", message: "发布成功" });
              this.handle.handle = 0;
              let l = data.data.length;
              if (l > 0) {
                for (var val of data.data) {
                  this.sendArrWebSocketTips(val.id);
                }
              }
              setTimeout(
                function () {
                  this.refreshFn();
                }.bind(this),
                100
              );
            } else {
              throwErrorTips("发布失败", data.msg);
            }
          }.bind(this),
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            location.reload();
          },
        });
      }
    },
    //直接发布
    releaseFn(id) {
      if (this.offDuty) {
        this.$Message({
          type: "error",
          message: "调度员暂不接单，请改用电话方式联系",
        });
        return;
      } else {
        let arr = [];
        arr.push(Number(id));
        this.handleUp(arr);
      }
    },
    //今日多单发布,显示选择多单
    releaseMoreFn() {
      let cid = this.$root.$data.cid;
      let atype = "post",
        adata = { opt: 1, day: today.tmr2(0, this.todayTime) };
      if (this.$root.$data.lineCid.indexOf(cid) != -1) {
        atype = "get";
        adata = { day: today.tmr2(0, this.todayTime), ks: this.hisks };
      }
      let m = this.$root.$data.hisErrTips[this.$root.$data.cid] || "";
      jQuery.ajax({
        url: this.$root.$data.hisLisUrl[cid],
        type: atype,
        dataType: "json",
        data: adata,
        cache: false,
        success: function (data) {
          if (data.success) {
            let lis = [
                {
                  address: "综合大楼负1楼放射科",
                  askdept: "雅和门诊",
                  bedno: "12",
                  canceltime: "2019-06-24 10:49:46",
                  createdtime: "2019-06-24 10:49:46",
                  dept: "CT室",
                  fixedtime: "2019-07-08 08:40 - 08:50",
                  guid: "1917755",
                  id: "607653",
                  memo: "",
                  name: "汪雯",
                  obey: "1",
                  statu: "0",
                  tasktime: "2019-06-24 10:49:49",
                  tour: "步行",
                },
                {
                  address: "综合大楼负1楼放射科",
                  askdept: "雅和门诊",
                  bedno: "21",
                  canceltime: "2019-06-24 10:49:46",
                  createdtime: "2019-06-24 10:49:46",
                  dept: "CT室",
                  fixedtime: "2019-07-08 08:40 - 08:50",
                  guid: "191773",
                  id: "607653",
                  memo: "",
                  name: "雅和",
                  obey: "1",
                  statu: "0",
                  tasktime: "2019-06-24 10:49:49",
                  tour: "步行",
                },
                {
                  address: "综合大楼负1楼放射科",
                  askdept: "雅和门诊",
                  bedno: "23",
                  canceltime: "2019-06-24 10:49:46",
                  createdtime: "2019-06-24 10:49:46",
                  dept: "CT室",
                  fixedtime: "2019-07-08 08:40 - 08:50",
                  guid: "191773",
                  id: "607653",
                  memo: "",
                  name: "21",
                  obey: "1",
                  statu: "0",
                  tasktime: "2019-06-24 10:49:49",
                  tour: "步行",
                },
                {
                  address: "综合大楼负1楼放射科",
                  askdept: "雅和门诊",
                  bedno: "01",
                  canceltime: "2019-06-24 10:49:46",
                  createdtime: "2019-06-24 10:49:46",
                  dept: "CT室",
                  fixedtime: "2019-07-08 08:40 - 08:50",
                  guid: "19177923",
                  id: "607653",
                  memo: "",
                  name: "21",
                  obey: "1",
                  statu: "0",
                  tasktime: "2019-06-24 10:49:49",
                  tour: "步行",
                },
                {
                  address: "综合大楼负1楼放射科",
                  askdept: "雅和门诊",
                  bedno: "12",
                  canceltime: "2019-06-24 10:49:46",
                  createdtime: "2019-06-24 10:49:46",
                  dept: "CT室",
                  fixedtime: "2019-07-08 08:40 - 08:50",
                  guid: "1917755",
                  id: "607653",
                  memo: "",
                  name: "汪雯",
                  obey: "1",
                  statu: "0",
                  tasktime: "2019-06-24 10:49:49",
                  tour: "步行",
                },
              ],
              nl = [],
              gl = [];
            lis = data.data.hisorder
              .concat(data.data.reservation)
              .sort(function (a, b) {
                if (/^\d/.test(a.bedno) ^ /^\D/.test(b.bedno))
                  return Number(a.bedno) > Number(b.bedno)
                    ? 1
                    : a.bedno == b.bedno
                    ? 0
                    : -1;
                return a.bedno > b.bedno ? -1 : a.bedno == b.bedno ? 0 : 1;
                //                                return a.bedno - b.bedno
              });
            for (var val of lis) {
              val["select"] = false;
              val["showlis"] = {
                names: val.name + " " + val.bedno,
                time: val.fixedtime.substring(11) || "",
              };
              gl.push(val.showlis.names);
            }
            gl = Array.from(new Set(gl));
            gl.forEach((v) => {
              let o = {
                name: v,
                lis: [],
              };
              lis.forEach((val) => {
                if (v == val.showlis.names) {
                  o.lis.push(val);
                }
              });
              nl.push(o);
            });
            this.moreLis = nl;
            this.isMore = true;
          } else {
            throwErrorTips("HIS单获取失败", data.msg, m);
          }
        }.bind(this),
        error: function (xhr, textStatus) {
          throwErrorTips("HIS单获取失败", xhr.status, m);
        }.bind(this),
      });
    },
    closeMoreFn() {
      this.isMore = false;
    },
    handlePrint(lis) {
      this.$parent.printLis = lis;
      this.$parent.isprint = true;
      this.$root.$data.printHis = true;
    },
    //今日单修改发布
    handleUpJson(json) {
      if (this.release == true) {
        this.release = false;
        jQuery.ajax({
          url: alterUrl,
          type: "post",
          dataType: "json",
          timeout: 1000,
          data: { data: JSON.stringify(json) },
          cache: false,
          success: function (data) {
            this.release = true;
            this.colsAlter();
            if (data.success) {
              this.$Message({ type: "success", message: "发布成功" });
              this.handle.handle = 0;
              this.sendArrWebSocketTips(data.data.id);
              setTimeout(
                function () {
                  this.refreshFn();
                }.bind(this),
                100
              );
            } else {
              throwErrorTips("发布失败", data.msg);
            }
          }.bind(this),
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            location.reload();
          },
        });
      }
    },
    alterFn() {
      this.isAlter.show = true;
      this.isAlter.type = 1;
    },
    //明天单修改发布
    toThisDayAlterFn() {
      this.isAlter.show = true;
      this.isAlter.type = 2;
    },
    colsAlter() {
      this.isAlter.show = false;
    },
    //明天单发布为今日单
    toThisDayReleaseFn() {
      this.isTomorrow.show = true;
      this.isTomorrow.type = 1;
    },
    //预约明天凌晨发布
    appointmentFn() {
      this.isTomorrow.show = true;
      this.isTomorrow.type = 2;
    },
    closeTom() {
      this.isTomorrow.show = false;
    },
    sureAppointment() {
      if (this.release == true) {
        this.release = false;
        jQuery.ajax({
          url: tomorrowUrl,
          type: "post",
          dataType: "json",
          timeout: 1000,
          data: { id: this.showLis.id, day: this.startTime.time },
          cache: false,
          success: function (data) {
            this.release = true;
            if (data.success) {
              this.$Message({ type: "success", message: "发布成功" });
              this.handle.handle = 0;
              setTimeout(
                function () {
                  this.refreshFn();
                }.bind(this),
                100
              );
            } else {
              throwErrorTips("发布失败", data.msg);
            }
          }.bind(this),
          error: function (XMLHttpRequest, textStatus) {
            location.reload();
          },
        });
      }
    },
    sureTomorrow() {
      if (this.offDuty) {
        this.$Message({
          type: "error",
          message: "调度员暂不接单，请改用电话方式联系",
        });
        return;
      } else {
        if (this.isTomorrow.type == 1) {
          //发布为今日单
          let arr = [];
          arr.push(Number(this.showLis.id));
          this.handleUp(arr);
        } else {
          //预约明天凌晨发布
          this.sureAppointment();
        }
      }
    },
    //催单
    reminderFn(id) {
      //销单,催单Ajax
      if (this.reminder) {
        this.reminder = false;
        if (this.issueShowLis.statu == 4) {
          this.sendObjWebSocketTips();
          setTimeout(
            function () {
              this.reminder = true;
              this.$Message({
                type: "success",
                message: "催单成功，等待指派人员！",
              });
            }.bind(this),
            1000
          );
        } else {
          jQuery.ajax({
            url: editUrl,
            type: "post",
            dataType: "json",
            cache: false,
            data: { opt: 1, oid: id },
            success: function (data) {
              this.reminder = true;
              if (data.success) {
                this.$Message({ type: "success", message: "催单成功！" });
                this.handle.handle = 0;
                this.refreshFn();
              } else {
                throwErrorTips("催单失败", data.msg);
              }
            }.bind(this),
            error: function (xhr, textStatus) {
              this.reminder = true;
            }.bind(this),
          });
        }
      }
    },
    //销单
    showCancelFn() {
      this.isCancel = true;
    },
    closeCancel() {
      this.isCancel = false;
    },
    cancelFn(des) {
      //销单
      if (this.cancel) {
        this.cancel = false;
        let dataj = { oid: this.issueShowLis.id };
        if (des) {
          dataj["msg"] = des;
        }
        jQuery.ajax({
          url: cancelUrl,
          type: "post",
          dataType: "json",
          data: dataj,
          cache: false,
          success: function (data) {
            this.cancel = true;
            if (data.success) {
              this.$Message({ type: "success", message: "销单成功" });
              this.handle.handle = 0;
              this.refreshFn();
            } else {
              throwErrorTips("销单失败", data.msg);
            }
          }.bind(this),
          error: function (xhr, textStatus) {
            this.cancel = true;
          }.bind(this),
        });
      }
    },
    //websocket
    sendObjWebSocketTips() {
      let json = {};
      json["istobg"] = true;
      json["uid"] = "";
      json["type"] = "1";
      json["otype"] = "待分配";

      json["id"] = String(this.issueShowLis.id);
      json["sn"] = this.issueShowLis.sn;
      json["classify"] = this.issueShowLis.classifyname;
      json["catalog"] = this.issueShowLis.catalogname;
      json["site"] = this.issueShowLis.startaddress;
      this.$emit("sendsocket", JSON.stringify(json));
    },
    sendArrWebSocketTips(id) {
      jQuery.ajax({
        url: infoUrl,
        type: "post",
        dataType: "json",
        cache: false,
        data: { oid: id },
        success: function (data) {
          if (data.success) {
            let info = data.data;
            if (info.statu == 4) {
              let json = {};
              json["istobg"] = true;
              json["uid"] = "";
              json["type"] = "1";
              json["otype"] = "待分配";

              json["id"] = String(info.id);
              json["sn"] = info.sn;
              json["classify"] = info.classifyname;
              json["catalog"] = info.catalogname;
              json["site"] = info.startaddress;
              this.$emit("sendsocket", JSON.stringify(json));
            }
          }
        }.bind(this),
      });
    },
  },
  created() {
    setTimeout(
      function () {
        if (this.todayTime != "") {
          this.refreshFn();
          window.clearInterval(sessionStorage.getItem("autoRefresh"));
        } else {
          location.reload();
        }
      }.bind(this),
      160
    );
  },
};
</script>
<style scoped lang="less">
@import "../assets/less/his.less";
</style>
